/*
 * comlan
 */

package com.promfy.designmode;

import java.util.ArrayList;
import java.util.List;

public class ObserverMode {
	public interface Listener{
		void onNotify();
	}
	
	public class Subject{
		private List<Listener> listeners ;
		private Object value;
		public Subject() {
			listeners = new ArrayList<Listener>();
			value = new Object();
		}
		
		public void register(Listener listener){
			listeners.add(listener);
		}
		
		public void unRegister(Listener listener){
			listeners.remove(listener);
		}
		
		public void setValue(Object value){
			this.value = value;
			sendNotify();
		}

		public Object getValue(){
			return value;
		}
		
		private void sendNotify() {
			for(Listener listener : listeners){
				listener.onNotify();
			}
		}
	}
}
